package com.sheng.project.demo;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.diagnosis.DiagnosisUtils;
import com.alipay.api.domain.AlipayDataDataserviceBillDownloadurlQueryModel;
import com.alipay.api.request.AlipayDataDataserviceBillDownloadurlQueryRequest;
import com.alipay.api.response.AlipayDataDataserviceBillDownloadurlQueryResponse;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.springframework.util.Assert;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * @author by ls
 * @date 2024/5/5
 */
public class AlipayDataDataserviceBillDownloadurlQuery {

    public static void main(String[] args) throws AlipayApiException {
//        String privateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCgd1VG8YmP6R9izhcTss9i3UZ+JlWh8PCLCheIvdepWXSus6JidkERCtM8DYcdaYVP7NfWOUn84qTK89GOFv0Ke0bSjKSOFwfZ1sN7sPegk/GHV2kRTwi7Av/0PTxUYZ4tkK/RCSGcORNp98SYjCCreQWzSEmHYTDM/JjFiMhSGSzqtNIzW0zixYuqm+gnsXDS6FggXXSLRKf0ccd1GFiZfo/VHuUV1KgvlNiFnAcI6I3crgxJnVFATc1B8lQtzmBJTRHlRBT9976O2xUo31uLUGq5WtZFgMYIz6qpyiHrK/pJy5ij1TLteeKa3JZK7EkPHa//GXnaWgB2eBYKnpTrAgMBAAECggEAck1uvlExVwSNKdl50LtPRLIwE44E84zoG3J93xazt1sUZZlps09e+9/FJgLQ2x+eKZehC2TVkkBzeGoDPH6dksjLYxFx6hD3s7FqoAIn8gdQRcL7AaxVoLj7T6QLBGRgwz5MLs+dVGXHsXUfYjZ20w4rBFEap0eQ9oN740GSx/8m9gOYMhxDfDNZu2UKEfKWCyZtbfLJnEbqSxAt7JooMGjNbwd8ro3hBXdRTSLbPbQ2DLBJvYCmGSZjKy1dYev/eZW8QUKhrWv3DXJNg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qs8200Lph6dopuMjClvgD1EasJ9Z523J4mBXOFRB94Euu0dg3bE0q6aVAm8XZZdiSvt3KPUtTLb4/fJD3rKUqdIt4/Ylq1ORRsV+gg6GGuAFdjg0wBs4hmIuvLRCE58U+zbGH8yHBzLF9qTpnXojswLW1hbSc4KFiev5Mi1D1fh0YOXTCVwyQIDAQAB";

        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setServerUrl("https://openapi.alipay.com/gateway.do");
        alipayConfig.setAppId("2021004143641304");
//        alipayConfig.setAppId("9021000128664782");
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setFormat("json");
        alipayConfig.setAlipayPublicKey(alipayPublicKey);
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        AlipayClient alipayClient = new DefaultAlipayClient(alipayConfig);
        AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
        AlipayDataDataserviceBillDownloadurlQueryModel model = new AlipayDataDataserviceBillDownloadurlQueryModel();
        model.setSmid("2088123412341234");
        model.setBillType("trade");
        model.setBillDate("2016-04-05");
        request.setBizModel(model);
        AlipayDataDataserviceBillDownloadurlQueryResponse response = alipayClient.execute(request);
        System.out.println(response.getBody());
        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
            String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
            System.out.println(diagnosisUrl);
        }
    }

    @Test
    public void test01() {
        String phone = "123";
        String code = "123";
        Assert.isTrue(StringUtils.isNotBlank(phone) && StringUtils.isNotBlank(code), "手机号/验证码不能为空");
        String format = LocalDate.now().minusDays(2).format(DateTimeFormatter.ISO_LOCAL_DATE);
        System.out.println(format);
    }
}
